import type { PurchaseContractVO, PurchaseContractForm, PurchaseContractQuery } from './model';

import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
* 查询采购合同列表
* @param params
* @returns 采购合同列表
*/
export function purchaseContractList(params?: PurchaseContractQuery) {
  return requestClient.get<PageResult<PurchaseContractVO>>('/trade/purchaseContract/list', { params });
}

/**
 * 导出采购合同列表
 * @param params
 * @returns 采购合同列表
 */
export function purchaseContractExport(params?: PurchaseContractQuery) {
  return commonExport('/trade/purchaseContract/export', params ?? {});
}

/**
 * 查询采购合同详情
 * @param id id
 * @returns 采购合同详情
 */
export function purchaseContractInfo(id: ID) {
  return requestClient.get<PurchaseContractVO>(`/trade/purchaseContract/${id}`);
}

/**
 * 新增采购合同
 * @param data
 * @returns void
 */
export function purchaseContractAdd(data: PurchaseContractForm) {
  return requestClient.postWithMsg<void>('/trade/purchaseContract', data);
}

/**
 * 更新采购合同
 * @param data
 * @returns void
 */
export function purchaseContractUpdate(data: PurchaseContractForm) {
  return requestClient.putWithMsg<void>('/trade/purchaseContract', data);
}

/**
 * 删除采购合同
 * @param id id
 * @returns void
 */
export function purchaseContractRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/trade/purchaseContract/${id}`);
}


/**
 * 根据订单查询采购合同信息，用于提交采购合同
 * @param data id集合
 * @returns void
 */
export function purchaseInfo(data: IDS) {
  return requestClient.post<PurchaseContractVO>(`/trade/purchaseContract/purchaseInfo`,data);
}

/**
 * 采购合同提交审核
 * @param data id集合
 * @returns void
 */
export function purchaseContractSubmit(data: IDS) {
  return requestClient.post<void>(`/trade/purchaseContract/submit`,data);
}

/**
 * 采购合同审核通过
 * @param id id
 * @returns void
 */
export function purchaseContractApprove(id: ID) {
  return requestClient.postWithMsg<void>(`/trade/purchaseContract/pass`,{id:id});
}

/**
 * 采购合同驳回
 * @param data 包含id和驳回原因
 * @returns void
 */
export function purchaseContractReject(data: { id: ID; rejectReason: string }) {
  return requestClient.postWithMsg<void>(`/trade/purchaseContract/reject`, data);
}

/**
 * 采购合同作废
 * @param data 包含id
 * @returns void
 */
export function purchaseContractInvalidate(data: { id: ID}) {
  return requestClient.postWithMsg<void>(`/trade/purchaseContract/invalidate`, data);
}
